package zuo.algo.c02;

import zuo.algo.util.SortUtils;

import java.util.Arrays;

public class BubblingSort {

    public static void sort(int[] arr) {
        int len = arr.length;
        for (int i = len; i > 0; i--) {
            for (int j = 1; j < i; j++) {
                if (arr[j] < arr[j-1]) {
                    SortUtils.swap(arr, j, j - 1);
                }
            }
        }
    }

    public static void main(String[] args) {
        int maxLen = 10000;
        for (int i = 0; i < 10000; i++) {
            int[] arr1 = SortUtils.getRandomArr(maxLen);
            int[] arr2 = Arrays.copyOf(arr1, arr1.length);
            sort(arr1);
            Arrays.sort(arr2);
            SortUtils.assertArr(arr1, arr2);
            System.out.println(i);
        }
    }
}
